<?php

/**
 * This is the model class for table "{{test_question}}".
 *
 * The followings are the available columns in table '{{test_question}}':
 * @property integer $question_id
 * @property string $question_content
 * @property string $question_tutorial
 * @property integer $form_id
 * @property integer $level_id
 *
 * The followings are the available model relations:
 * @property TestLevel $level
 * @property TestForm $form
 */
class TestQuestion extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return TestQuestion the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return '{{test_question}}';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('question_content', 'required'),
			array('form_id, level_id', 'numerical', 'integerOnly'=>true),
			array('question_content, question_tutorial', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('question_id, question_content, question_tutorial, form_id, level_id', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'level' => array(self::BELONGS_TO, 'TestLevel', 'level_id'),
			'form' => array(self::BELONGS_TO, 'TestForm', 'form_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'question_id' => 'Question',
			'question_content' => 'Question Content',
			'question_tutorial' => 'Question Tutorial',
			'form_id' => 'Form',
			'level_id' => 'Level',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('question_id',$this->question_id);
		$criteria->compare('question_content',$this->question_content,true);
		$criteria->compare('question_tutorial',$this->question_tutorial,true);
		$criteria->compare('form_id',$this->form_id);
		$criteria->compare('level_id',$this->level_id);

		return new CActiveDataProvider(get_class($this), array(
			'criteria'=>$criteria,
		));
	}
}